home *** CD-ROM | disk | FTP | other *** search
- Path: anvil.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: microseconds??
- Date: 1 Mar 1996 12:42:05 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4h7netINN1hk@anvil.ugrad.cs.ubc.ca>
- References: <4h62s9$2o7@chaos.dac.neu.edu>
- NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
-
- In article <4h62s9$2o7@chaos.dac.neu.edu>,
- hadi abedi <habedi@lynx.dac.neu.edu> wrote:
- >Hello,
- > Thanks for taking your time to read this.
- >
- > Is there a way to compute microsecond intervals
- > with C?
- > I'd like to time a sorting routine on different
- > list sizes. I am aware of the 'time' function on
- > the UNIX system, but I'd like to know how to do
- > it in C.
- > Thanks.
-
- The _best_ way to do this under a particular environment is up to, well, that
- particular environment. The standard C way of timing is the the clock()
- function. Converting to seconds means dividing by the symbolic constant
- CLOCKS_PER_SEC defined in <time.h>. Hopefully, this is a few order of
- magnitudes greater than 1.
-
- On this HP-UX system, the actual value is:
-
- /* ANSI C time constants, types, and structures */
-
- #ifdef _INCLUDE__STDC__
- # define CLOCKS_PER_SEC 1000000
-
- # ifndef NULL
- # define NULL 0
- # endif
-
-
- So you see, the clock() function can have microsecond resolution (I'm not
- saying that the hardware does, just the clock() function).
-
- It's likely that it is implemented with the best possible method that yields
- the greatest resolution. The above clearly shows that CLOCKS_PER_SEC does not
- have to be restricted to the preemptive clock frequency of the operating system
- (i.e. the HZ value).
- --
-
-